package cn.zhentao.dao;

import cn.zhentao.pojo.Emp;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface EmpMapper {
    //一对一查询
    @Select("select * from emp")
    @Results(
            id = "empMap", value = {
            @Result(id = true, column = "empno", property = "empno"),
            @Result(column = "ename", property = "ename"),
            @Result(column = "job", property = "job"),
            @Result(column = "mgr", property = "mgr"),
            @Result(column = "hiredate", property = "hiredate"),
            @Result(column = "sal", property = "sal"),
            @Result(column = "comm", property = "comm"),
            @Result(column = "deptno",property = "dept" ,one =                             //懒加载
                            @One(select="cn.zhentao.dao.DeptMapper.findByNo",fetchType = FetchType.LAZY))
    }
    )
    List<Emp> findAll();

    @Select("select * from emp where empno=#{empno}")
    Emp findByNO(int empno);

    @Select("select * from emp where deptno=#{deptno}")
    List<Emp> findByDeptNo(int deptno);

//    @Select("select * from emp")
//    List<Emp> findAll2();


}
